package com.niguang.work.api.entity;

import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import com.baomidou.mybatisplus.enums.IdType;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.niguang.work.api.enums.ContentApplyFlagEnum;
import com.niguang.work.api.enums.DangerLevelEnum;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>
 * 'work.v_personSite' is not BASE TABLE
 * </p>
 *
 * @author 12380
 * @since 2018-09-06
 */
@TableName("work_reform_content")
@Data
public class ReformContent extends Model<ReformContent> {

    private static final long serialVersionUID = 1L;

    @JsonIgnore
    @TableId(value = "id", type = IdType.ID_WORKER)
    private Long id;

    @TableField(exist = false)
    private String subId;
    /**
     * 提交人openId
     */
    private String openId;
    /**
     * 提交人userId
     */
    private String userId;

    /**
     * 提交人电话号码
     */
    private String userPhone;

    private String userName;
    /**
     * 工作职位
     */
    private String jobPosition;
    /**
     * 工地ID
     */
    @NotNull(message = "项目[siteId]不能为空！")
    private Long siteId;
    /**
     * 项目名称
     */
    private String siteName;
    /**
     * 积分
     */
    private Integer integral;

    /**
     * 隐患部位
     */
    @NotBlank(message = "隐患部位不能为空！")
    private String dangerTitle;
    /**
     * 隐患图片
     */
    @NotBlank(message = "隐患图片不能为空！")
    private String dangerPic;

    /**
     * 图片转换数组
     */
    @TableField(exist = false)
    private String[] dangerPicArr;
    /**
     * 隐患描述
     */
    @NotBlank(message = "隐患描述不能为空！")
    private String dangerDesc;
    /**
     * 是否启用(启用后放入需求池)  0-启用 1-不启用
     */
    private Integer enableFlag;

    /**
     * 隐患级别 1-一般 2-较大 3-重大 4-特大
     */
    private Integer dangerLevel;

    @TableField(exist = false)
    private String dangerLevelText;

    /**
     * 整改期限
     */
    private String reformTerm;

    /**
     * 上报类型 1--安全隐患 2--质量隐患
     */
    @NotNull(message = "上报类型不能为空！")
    private Integer formFlag;
    /**
     * 审核状态 1-待审核 2-无需整改 3-待整改 4-待复查 5-已完成
     */
    private Integer applyFlag;

    @TableField(exist = false)
    private String applyFlagText;

    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @TableField(exist = false)
    private String createTimeFormt;

    @JsonIgnore
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

    private String unionId;


    public String getDangerLevelText() {
        return DangerLevelEnum.getName(dangerLevel);
    }

    public String getSubId() {
        return this.id + "";
    }

    public String[] getDangerPicArr() {
        if (StringUtils.isNotBlank(dangerPic)) {
            return dangerPic.split(";");
        }
        return new String[]{};
    }

    public String getCreateTimeFormt() {
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd");
        if (createTime != null) {
            return sdf.format(this.createTime);
        }
        return createTimeFormt;
    }

    public ReformContent() {
    }

    public ReformContent(Long id, Integer dangerLevel, String reformTerm) {
        this.id = id;
        this.dangerLevel = dangerLevel;
        this.reformTerm = reformTerm;
    }

    /**
     * 修改提交人表单数据状态
     */
    public ReformContent(Long id, Integer integral, Integer applyFlag, Integer enableFlag) {
        this.id = id;
        this.integral = integral;
        this.applyFlag = applyFlag;
        this.enableFlag = enableFlag;
    }

    /**
     * 审核节点操作审核状态
     */
    public ReformContent(Long id, Integer applyFlag) {
        this.id = id;
        this.applyFlag = applyFlag;
    }

    public String getApplyFlagText() {
        return ContentApplyFlagEnum.getName(applyFlag);
    }

    public static final String ID = "id";

    public static final String OPEN_ID = "open_id";

    public static final String USER_ID = "user_id";

    public static final String USER_PHONE = "user_phone";

    public static final String JOB_POSITION = "job_position";

    public static final String SITE_ID = "site_id";

    public static final String SITE_NAME = "site_name";

    public static final String INTEGRAL = "integral";

    public static final String DANGER_PIC = "danger_pic";

    public static final String DANGER_DESC = "danger_desc";

    public static final String ENABLE_FLAG = "enable_flag";

    public static final String APPLY_FLAG = "apply_flag";

    public static final String CREATE_TIME = "create_time";

    public static final String UPDATE_TIME = "update_time";

    public static final String FORM_FLAG = "form_flag";

    public static final String UNION_ID = "union_id";


    @Override
    protected Serializable pkVal() {
        return this.id;
    }
}
